This code sample demonstrates how to raise an alarm toast notification that includes Snooze and Dismiss buttons. Alarm toasts are available as of Windows 8.1.
One lock screen app can be designated by the user as the system alarm app, either through PC Settings or by accepting a permissions dialog. Once a lock screen app is designated as the system alarm app, it can schedule alarm notifications that are shown to the user within an accuracy of one second.
This sample demonstrates the following functionality for alarm apps:
- Raising an alarm toast notification
- Setting a custom snooze duration for an alarm toast
For general toast notification sample code, see the Toast notifications sample.
An app that has a lock screen presence must declare one or more of the following types of background tasks:
- Control channel
- Timer
- Push notification
In the Microsoft Visual Studio manifest editor, this background task value is set in the
Declarations tab. This sets the BackgroundTasks element in the
package.appxmanifest file. The background task typically runs periodically to schedule new alarms, recurring alarms, or both. This sample uses a placeholder background task that is never scheduled.
To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.
To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.
Note For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.
Related topics
- New API for alarm apps
- Toast schema commands element
- AlarmApplicationManager
- Toast notifications sample
- Lock screen apps sample
- Windows app samples
Operating system requirements
| Client | |
|---|---|
| Server |
Build the sample
- Download the sample's .zip file using one of the buttons near the top of the page.
- Unzip the downloaded file into a folder on your computer.
- Start Visual Studio 2013 and select File > Open > Project/Solution.
- Go to the folder where you unzipped the sample.
- Find and open the folder named for the sample and one of its programming language subfolders (C#, JS.
- Double-click the Visual Studio Solution (.sln) file to open it.
- Use Build > Build Solution to build the sample.
Run the sample
To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.
The first time (and only the first time) that you run the app, you will be shown a dialog that asks "Replace your current alarm app with this one?" To see the alarm on the lock screen, or to see it elsewhere with its snooze and dismiss buttons, you should select "Yes". If you do not, you can replace the current alarm app with the sample app manually later through PC Settings. The only way to see the original dialog again is to uninstall and reinstall the app.
To use the sample:
- Select a delay time to specify the amount of time before the alarm appears. This must be between 1 and 60 minutes (inclusive).
- Either click the Default Snooze button to use the default snooze time of approximately 9 minutes or set a snooze time and set the Custom Snooze button.
- Wait for the alarm to appear or lock your computer (for instance by pressing Windows logo key + L) to take you to the lock screen to see the alarm there.
- When the alarm appears, you can take these actions:
- Select snooze. The alarm will reappear after the specified or default time.
- Select dismiss.
- Do nothing and the toast will dismiss itself after a time
If the alarm does not appear on the lock screen, go to PC Settings to ensure that the alarm notification sample is set as the alarm app.
Note that if you do not set the alarm notification app as the system alarm app, you can still see the alarm everywhere except the lock screen. However, it will not have the snooze or dismiss buttons. In that case, you have these options:
- Click or touch the toast body to launch the app.
- Click the X (visible on mouse-over) or swipe the toast to dismiss it
- Do nothing and the toast will dismiss itself after a time